import request from "../../request";

const api = {
    login: '/admin/user/login',
    register: '/admin/user/register',
    getUser: '/admin/user/all',
    update: '/admin/user/update',
    save: '/admin/user/save',
    deleteId: '/admin/user/delete/id=',
    delbatch: '/admin/user/del/batch',
    userById: '/admin/user/get-user/id=',
    userPage: '/admin/user/page',
    findUserInfo: '/admin/user/username'
}

/**
 * 登录 
 * @param data
 * @returns {AxiosPromise}
 */
export function loginUser(param){
    return request({
        url: api.login,
        method: 'POST',
        data: param
    })
}

/**
 * 注册
 * @param data
 * @returns {AxiosPromise}
 */
export function registerUser(param){
    return request({
        url: api.register,
        method: 'POST',
        data: param
    })
}

/**
 * 添加
 * @param data
 * @returns {AxiosPromise}
 */
export function saveUserData(param){
    return request({
        url: api.save,
        method: 'POST',
        data: param
    })
}


/**
 * 根据id进行删除
 * @returns {AxiosPromise}
 */
export function delUserByid(id){
  return request({
      url: api.deleteId + id,
      method: 'GET'
  })
}

/**
 * 批量删除
 * @param ids
 * @returns {AxiosPromise}
 */
export function delUserBatch(ids){
  return request({
      url: api.delbatch,
      method: 'POST',
      data: ids
  })
}

/**
 * 修改
 * @param data
 * @returns {AxiosPromise}
 */
export function updateUser(param){
  return request({
      url: api.update,
      method: 'POST',
      data: param
  })
}

/**
 * 查询全部数据
 * @returns {AxiosPromise}
 */
export function getAllUser(){
  return request({
      url: api.getUser,
      method: 'GET',
  })
}

/**
 * 根据id进行查询
 * @returns {AxiosPromise}
 */
export function getUserByid(id){
  return request({
      url: api.userById + id,
      method: 'GET'
  })
}
/**
 * 根据用户名进行查询
 * @returns {AxiosPromise}
 */
export function getUserByUsername(param){
    return request({
        url: api.userById + id,
        method: 'GET',
        params: param
    })
  }

/**
 * 分页查询
 * @param data
 * @returns {AxiosPromise}
 */
export function getUserPage(param){
  return request({
      url: api.userPage,
      method: 'GET',
      params: param
  })
}